ENV["RAILS_ENV"] = "test"
require File.expand_path(File.dirname(__FILE__) + "/../../../../config/environment")
require 'test_help'
require File.expand_path(File.dirname(__FILE__) + "/../lib/combination")
# require 'test/unit'
ActiveSupport::TestCase.fixture_path=File.expand_path(File.dirname(__FILE__) + "/fixtures")


class ActiveSupport::TestCase
  def self.generate_rrule_bymonth_data
    gen_all_combos(Rical::RruleBymonth, "m", 1)
  end

  def self.generate_rrule_byday_data
    gen_all_combos(Rical::RruleByday, "d", 0)
  end
  
  #generating the data is several orders of magnitude
  #faster than parsing flat file
  #TODO: can make this even more efficient by doing
  #      a bulk insert with straight sql
  #      rather than individual inserts
  def self.gen_all_combos(klass, field_prefix, offset)
    columns = klass.column_names
    columns.length.times do |i|
      combos = Rical::Combination.get(columns.length-1, i+1)
      combos.each do |combo|
        k = klass.new
        combo.each do |cell|
          k.send("#{field_prefix}#{cell+offset}=", true)
        end
        k.save!
      end

    end
  end
end